# Bombs-Must-Detonate : BMDLang Compiler Makefile
# Author: Brian Go

## MAKEFILE ##
all: compiler linker docs
clean: 
	rm *.cmi *.cmo bmdlex.ml bmdparse.ml bmdparse.mli bmdlinklex.ml bmdlinkparse.ml bmdlinkparse.mli *.output *~ bmdc

# AST DEF #
ast:
	ocamlc -c ast.mli
	ocamlc -c ast.ml

# LINKER AST #
linkst:
	ocamlc -c linkst.mli

# LEXER & PARSER #
lexparse:
	export OCAMLRUNPARAM='p'
	ocamllex bmdlex.mll
	ocamlyacc -v bmdparse.mly
	ocamlc -c bmdparse.mli
	ocamlc -c bmdlex.ml
	ocamlc -c bmdparse.ml

# LINKER LEXER & PARSER #
linklexparse:
	export OCAMLRUNPARAM='p'
	ocamllex bmdlinklex.mll
	ocamlyacc -v bmdlinkparse.mly
	ocamlc -c bmdlinkparse.mli
	ocamlc -c bmdlinklex.ml
	ocamlc -c bmdlinkparse.ml

# FSM SYNTAX EXTENSION
fsm:
	ocamlc -c bmdfsmc.mli
	ocamlc -c bmdfsmc.ml

# TYPECHECKER
typecheck:
	ocamlc -c bmdtc.mli
	ocamlc -c bmdtc.ml

# IR COMPILER
irc:
	ocamlc -c bmdirc.mli
	ocamlc -c bmdirc.ml

# FINAL COMPILER
fc:
	ocamlc -c bmdfc.mli
	ocamlc -c bmdfc.ml

# --------------------------- 

# COMPILER EXECUTABLE #
compiler: ast lexparse fsm typecheck irc fc
	ocamlc -c bmdc.ml
	ocamlc -o bmdc bmdlex.cmo bmdparse.cmo ast.cmo bmdfsmc.cmo bmdtc.cmo bmdirc.cmo bmdfc.cmo bmdc.cmo

# LINKER EXECUTABLE #
linker: linkst linklexparse
	ocamlc -c bmdl.ml
	ocamlc -o bmdl bmdlinklex.cmo bmdlinkparse.cmo bmdl.cmo

# OCAMLDOC DOCS #
docs: *t.ml *c.ml *t.mli *c.mli
	ocamldoc -html -keep-code -inv-merge-ml-mli -m A -d ocamldocs *t.ml *c.ml *t.mli *c.mli bmdl.ml